package com.som.beanconvert.data2.output;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.ss.usermodel.Row;

import com.som.bean.data2.output.AllSystemSameData;
import com.som.beanconvert.ExcelColumnProcessInf;
import com.som.beanconvert.ExcelDataParseOutputInf;
import com.som.console.PathEnum;
import com.som.util.FileUtils;

/**
 * 通过LOOPBACK地址让数据二与数据三关联 以设备采集的数据为准 输出列为: IP地址 路由(network) 网元信息 区县
 * 
 * @author liujun
 * @date 2016年4月8日
 * @verion 0.0.1
 */
public class AllSystemSameDataExcelOutput extends AllSystemSameData implements ExcelDataParseOutputInf<AllSystemSameData>, ExcelColumnProcessInf
{

	public void parseExcelRow(AllSystemSameData beaninfo, Row row)
	{

		HSSFRow hrow = (HSSFRow) row;

		// 设置ip信息
		HSSFCell cellIp = hrow.createCell(0);
		cellIp.setCellType(HSSFCell.CELL_TYPE_STRING);
		cellIp.setCellValue(beaninfo.getIpaddress());

		LinkedList<String> systemName = beaninfo.getSystemName();

		if (null != systemName && !systemName.isEmpty())
		{
			Iterator<String> iter = systemName.iterator();
			int index = 1;
			String value = null;

			while (iter.hasNext())
			{
				value = iter.next();

				HSSFCell cellValue = hrow.createCell(index);
				cellValue.setCellType(HSSFCell.CELL_TYPE_STRING);
				cellValue.setCellValue(value);
				index++;
			}
		}

	}

	public static void main(String[] args)
	{
		Map<String, String> map = new LinkedHashMap<String, String>();

		for (int i = 0; i < 100; i++)
		{
			map.put(String.valueOf(i), String.valueOf(i));
		}

		Iterator<Entry<String, String>> mapIter = map.entrySet().iterator();

		Entry<String, String> entry = null;

		while (mapIter.hasNext())
		{
			entry = mapIter.next();
			System.out.println(entry.getKey() + ":" + entry.getValue());
		}
	}

	public void setExcelColumn(Map<String, String> column, Row row)
	{
		HSSFRow hrow = (HSSFRow) row;

		// 设置ip信息
		HSSFCell cellIp = hrow.createCell(0);
		cellIp.setCellType(HSSFCell.CELL_TYPE_STRING);
		cellIp.setCellValue("IP");

		if (null != column && !column.isEmpty())
		{
			Iterator<Entry<String, String>> columnMapIter = column.entrySet().iterator();

			int index = 1;
			Entry<String, String> entry = null;

			String key = null;

			while (columnMapIter.hasNext())
			{
				entry = columnMapIter.next();
				key = entry.getKey();

				// 只有包括标识为多文件的才进行读取
				if (null != key && key.contains(PathEnum.DATA2_INPUT_COMPINPUT.getPathFlag()))
				{
					// 设置其他输出信息
					HSSFCell cellName = hrow.createCell(index);
					cellName.setCellType(HSSFCell.CELL_TYPE_STRING);
					cellName.setCellValue(FileUtils.getFileName(entry.getValue()));
					index++;
				}

			}
		}
	}

}
